﻿package view.task
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.ybstore.consts.*;

    public class ActivityGongChengCtrl extends ActivityGongchengUI
    {
        private var _timerid:uint = 0;
        private var _lasttime1:int = 0;
        private var _lasttime2:int = 0;
        private static const Maxbo:int = 5;
        private static const BoTime:int = 180;

        public function ActivityGongChengCtrl()
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this.txt_ph.addEventListener(MouseEvent.ROLL_OVER, this.rollOver);
            this.txt_ph.addEventListener(MouseEvent.ROLL_OUT, this.rollOut);
            this.rankview.list.renderHandler = new Handler(this.listHandler);
            this.txt_buy.addEventListener(MouseEvent.CLICK, this.clickHandler);
            this.rankview.list.array = [];
            no1.text = "1." + "暂无";
            no2.text = "2." + "暂无";
            no3.text = "3." + "暂无";
            this.txt_sm.toolTip = "活动一共5波怪物，每波怪物200只，分布于热血城任意角落，每波怪物都携带大量经验！该活动持续40分钟，活动时间结束后，则所有怪物都会消失！";
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("store", CMDStore.GetPrice, 37);
            return;
        }// end function

        private function listHandler(param1:Box, param2:int) : void
        {
            var _loc_3:* = param1.getChildByName("ranktxt") as Label;
            var _loc_4:* = param1.getChildByName("nametxt") as Label;
            var _loc_5:* = param1.getChildByName("count") as Label;
            var _loc_6:* = this.rankview.list.array[param2];
            if (this.rankview.list.array[param2])
            {
                _loc_3.text = int((param2 + 1)) + "";
                _loc_4.text = _loc_6[0];
                _loc_5.text = _loc_6[1];
            }
            else
            {
                _loc_3.text = int((param2 + 1)) + "";
                _loc_4.text = "";
                _loc_5.text = "";
            }
            return;
        }// end function

        protected function rollOut(event:MouseEvent) : void
        {
            rankview.visible = false;
            return;
        }// end function

        protected function rollOver(event:MouseEvent) : void
        {
            rankview.visible = true;
            return;
        }// end function

        public function updateHdGcz(param1:Object) : void
        {
            this.rankview.list.array = param1 as Array;
            if (param1[0])
            {
                no1.text = "1." + param1[0][0] + "(" + param1[0][1] + "击杀)";
            }
            else
            {
                no1.text = "1." + "暂无";
            }
            if (param1[1])
            {
                no2.text = "2." + param1[1][0] + "(" + param1[1][1] + "击杀)";
            }
            else
            {
                no2.text = "2." + "暂无";
            }
            if (param1[2])
            {
                no3.text = "3." + param1[2][0] + "(" + param1[2][1] + "击杀)";
            }
            else
            {
                no3.text = "3." + "暂无";
            }
            return;
        }// end function

        public function init() : void
        {
            this.rankview.list.array = [];
            no1.text = "1." + "暂无";
            no2.text = "2." + "暂无";
            no3.text = "3." + "暂无";
            return;
        }// end function

        public function end() : void
        {
            if (this._timerid > 0)
            {
                SecondTimerUtil.instance.removeTask(this._timerid);
                this._timerid = 0;
            }
            return;
        }// end function

        public function updateMonsterTime(param1:Object) : void
        {
            txt_bo.text = param1[0];
            if (this._timerid == 0)
            {
                this._timerid = SecondTimerUtil.instance.addSecondTask(this.timerHandler);
            }
            var _loc_2:* = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
            if (param1[0] < Maxbo)
            {
                this._lasttime1 = param1[1] - _loc_2;
                this._lasttime2 = int(param1[2] - _loc_2);
                txt_ntime.text = TimeDataFormatUtil.getLeftTime2(this._lasttime1);
                txt_time.text = TimeDataFormatUtil.getLeftTime2(this._lasttime2);
            }
            else
            {
                this._lasttime1 = 0;
                this._lasttime2 = int(param1[2] - _loc_2);
                txt_ntime.text = "--";
                txt_time.text = TimeDataFormatUtil.getLeftTime2(this._lasttime2);
            }
            return;
        }// end function

        private function timerHandler() : void
        {
            if (this._lasttime1 > 0)
            {
                var _loc_1:String = this;
                var _loc_2:* = this._lasttime1 - 1;
                _loc_1._lasttime1 = _loc_2;
                txt_ntime.text = TimeDataFormatUtil.getLeftTime2(this._lasttime1);
            }
            else
            {
                txt_ntime.text = "--";
            }
            if (this._lasttime2 > 0)
            {
                var _loc_1:String = this;
                var _loc_2:* = this._lasttime2 - 1;
                _loc_1._lasttime2 = _loc_2;
                txt_time.text = TimeDataFormatUtil.getLeftTime2(this._lasttime2);
            }
            return;
        }// end function

    }
}
